/*
 * Copyright (C) 2017-2025
 * All rights reserved, Designed By 深圳中科鑫智科技有限公司
 * Copyright authorization contact 18814114118
 */
package com.shop.zkmall.admin;

import com.shop.zkmall.admin.service.label.CerePlatformLabelService;
import com.shop.zkmall.admin.service.redis.CereRedisKeyService;
import com.shop.zkmall.admin.service.shop.CerePlatformShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableAsync;

@EnableAsync
@SpringBootApplication(scanBasePackages = {"com.shop.zkmall.commons.utils","com.shop.zkmall.admin","com.shop.zkmall.commons.config"})
public class CereshopAdminApplication extends SpringBootServletInitializer implements CommandLineRunner {

    @Autowired
    private CerePlatformLabelService cerePlatformLabelService;

    @Autowired
    private CerePlatformShopService cerePlatformShopService;

    @Autowired
    private CereRedisKeyService cereRedisKeyService;

    /**
     * 需要把web项目打成war包部署到外部tomcat运行时需要改变启动方式
     */
    @Override  //重写configure方法，把springboot的入口给它
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(CereshopAdminApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(CereshopAdminApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        //        //开启自动绑定标签定时任务
//        TimingTask timingTask=new TimingTask();
//        ScheduledFuture<?> labelFuture = timingTask.startExtensionInitialization("0 0 0 * * ?",
//                new LabelInitializationRunnable(cerePlatformLabelService));
//        //开启分销员等级自动升级定时任务
//        ScheduledFuture<?> LevelFutrue = timingTask.startAutomaticUpgradeInitialization("0 0 0 * * ?",
//                new DistributionLevelInitializationRunnable(cereShopDistributionLevelService));
//        //开启商家合同有效期截止自动禁用定时任务
//        ScheduledFuture<?> shopFutrue = timingTask.startStopShopInitialization("0 0 0 * * ?",
//                new ShopInitializationRunnable(cerePlatformShopService));
        try {
            //初始化Redis延时任务
            cereRedisKeyService.initializationRedis();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            System.out.println("------   admin-server启动成功    ------\n");
        }
    }
}
